home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / etc / cron.daily / popularity-contest < prev    next >
Text File  |  2009-06-16  |  2KB  |  97 lines

  1. #!/bin/sh
  2.  
  3. # don't run if this package is removed but not purged
  4. if [ ! -f /usr/sbin/popularity-contest ]; then
  5.     exit 0
  6. fi
  7.  
  8. unset MAILFROM
  9. unset MAILTO
  10. unset MY_HOSTID
  11. unset PARTICIPATE
  12. unset SUBMITURLS
  13. unset USEHTTP
  14.  
  15. # get configuration information
  16. . /usr/share/popularity-contest/default.conf
  17. . /etc/popularity-contest.conf
  18.  
  19. # don't run if MAILTO address is blank, and not configured to use HTTP POST!
  20. if [ -z "$MAILTO" ] && [ "yes" != "$USEHTTP" ]; then exit 0; fi
  21.  
  22. # don't run if PARTICIPATE is "no" or unset!
  23. [ "$PARTICIPATE" = "no" ] || [ -z "$PARTICIPATE" ] && exit 0
  24.  
  25. if [ -n "$HTTP_PROXY" ]; then
  26.   export http_proxy="$HTTP_PROXY";
  27. fi
  28.  
  29. # Only run on the given day, to spread the load on the server a bit
  30. if [ "$DAY" ] && [ "$DAY" != "$(date +%w)" ] ; then
  31.   exit 0
  32. fi
  33.  
  34. # keep old logs
  35. cd /var/log
  36. umask 022
  37. savelog -c 7 popularity-contest >/dev/null
  38. POPCON=/var/log/popularity-contest
  39.  
  40. run_popcon()
  41. {
  42.     su -s /bin/sh -c "/usr/sbin/popularity-contest" nobody
  43. }
  44.  
  45. do_sendmail()
  46. {
  47.     if [ -n "$MAILFROM" ]; then
  48.         sendmail -oi -f "$MAILFROM" $MAILTO
  49.     else
  50.         sendmail -oi $MAILTO
  51.     fi
  52. }
  53.  
  54. # generate the popularity contest data
  55.  
  56. run_popcon > $POPCON
  57.  
  58. SUBMITTED=no
  59.  
  60. # try to post the report through http POST
  61. if [ "$SUBMITURLS" ] && [ "yes" = "$USEHTTP" ]; then
  62.     for URL in $SUBMITURLS ; do
  63.     if setsid /usr/share/popularity-contest/popcon-upload \
  64.         -u $URL -f $POPCON -C 2>/dev/null ; then
  65.         SUBMITTED=yes
  66.     else
  67.         logger -t popularity-contest "unable to submit report to $URL."
  68.     fi
  69.     done
  70. fi
  71.  
  72. # try to email the popularity contest data
  73.  
  74. if [ yes != "$SUBMITTED" ] && [ -n "$MAILTO" ]; then
  75.     if [ -x "`which sendmail 2>/dev/null`" ]; then
  76.     (
  77.         if [ -n "$MAILFROM" ]; then
  78.                 echo "From: <$MAILFROM>"
  79.             echo "Sender: <$MAILFROM>"
  80.         fi
  81.         echo "To: $MAILTO"
  82.         echo "Subject: popularity-contest submission"
  83.         echo "MIME-Version: 1.0"
  84.         echo "Content-Type: text/plain"
  85.         echo
  86.         cat $POPCON
  87.     ) | do_sendmail
  88.     SUBMITTED=yes
  89.     else
  90.     logger -t popularity-contest "unable to submit report using sendmail."
  91.     fi
  92. fi
  93.  
  94. if [ "yes" != "$SUBMITTED" ] ; then
  95.     logger -t popularity-contest "unable to submit report."
  96. fi
  97.